/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.upc.virtes;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author acardenas
 */
public class ConexionPgSQL {
    private Connection conn;
    private ResultSet rs;
    public String s;

    public void ConexionPgsql() {
        String url="";
        try {
            Class.forName("org.postgresql.Driver");
            url="jdbc:postgresql://localhost/virtes";
            try {
                conn = DriverManager.getConnection(url, "postgres", "kasuya");
            } catch (SQLException ex) {
                Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void QuerySQL(String sqlQuery) {
        try {
            rs = this.getConn().createStatement().executeQuery(sqlQuery);
        } catch (SQLException ex) {
            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void QueryInsertSQL(String sqlQuery) {
        try {
            //this.getConn().createStatement().executeQuery(sqlQuery);
            this.getConn().createStatement().execute(sqlQuery);

        } catch (SQLException ex) {
            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void QueryUpdateSQL(String sqlQuery) {
        try {
            //this.getConn().createStatement().executeQuery(sqlQuery);
            this.getConn().createStatement().execute(sqlQuery);

        } catch (SQLException ex) {
            Logger.getLogger(ConexionPgSQL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void CloseConnection() throws SQLException {
        this.getConn().close();
    }

    /**
     * @return the conn
     */
    public Connection getConn() {
        return conn;
    }

    /**
     * @return the rs
     */
    public ResultSet getRs() {
        return rs;
    }
}
